package entity;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

@Entity @Table(name="TREATMENT_REQUESTS")
@NamedQueries({ 
@NamedQuery(name = "TreatmentRequest.selectDoctorNamesByActId", query = "SELECT DISTINCT concat(t.doctor.firstName, ' ', t.doctor.lastName) " +
		"FROM TreatmentRequest t WHERE t.act.id = :actId"), 
@NamedQuery(name = "TreatmentRequest.selectRequestsByDoctorIdAndDateRange", query = "SELECT t FROM TreatmentRequest t " +
		"WHERE t.doctor.id = :doctorId AND t.meetDate >= :startDate AND t.meetDate < :endDate ORDER BY t.meetDate"), 
@NamedQuery(name = "TreatmentRequest.selectRequestsByDateRange", query = "SELECT t FROM TreatmentRequest t " +
		"WHERE t.meetDate >= :startDate AND t.meetDate < :endDate ORDER BY t.meetDate")
})
public class TreatmentRequest {	
	
	@Id
	@Column(name = "REQ_ID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DEF_GEN")    
	@SequenceGenerator(name = "DEF_GEN", sequenceName = "REQ_ID_SEQ", allocationSize=1)
    private int id;
	
	@NotNull(message="Meet date cannot be empty")
	@Temporal(TemporalType.TIMESTAMP)    
	@Column(name = "MEET_DATE") 
	private Calendar meetDate;
	
	@Column(name = "ACCEPT_STATUS", nullable = false) 
	private boolean acceptStatus;
	
	@ManyToOne
	@JoinColumn(name = "ACT_ID", nullable = false)
	private TreatmentAct act;
	
	@ManyToOne
	@JoinColumn(name = "DOCTOR_ID", nullable = false)
	private Doctor doctor;
	
	public TreatmentRequest() { }
	
	public TreatmentRequest(Calendar meetDate, boolean status, TreatmentAct act, Doctor doctor) {
		this.meetDate = meetDate;
		this.acceptStatus = status;
		this.act = act;
		this.doctor = doctor;
	}
	
	public int getId() {
        return id;
    }
 
    public void setId(int id) {
        this.id = id;
    }

	public Calendar getMeetDate() {
		return meetDate;
	}

	public void setMeetDate(Calendar meetDate) {
		this.meetDate = meetDate;
	}

	public boolean isAcceptStatus() {
		return acceptStatus;
	}

	public void setAcceptStatus(boolean acceptStatus) {
		this.acceptStatus = acceptStatus;
	}

	public TreatmentAct getAct() {
		return act;
	}

	public void setAct(TreatmentAct act) {
		this.act = act;
	}

	public Doctor getDoctor() {
		return doctor;
	}

	public void setDoctor(Doctor doctor) {
		this.doctor = doctor;
	}
	
}